<?php

declare (strict_types=1);

namespace app\store\controller\agent;

use app\store\controller\Controller;
use think\App;
use think\response\Json;
use app\store\service\agent\Achievement as AchievementService;

/**
 * 业绩相关
 * Class Setting
 * @package app\store\controller
 */
class Achievement extends Controller
{
    private $achievementService;
    public function __construct(App $app,AchievementService $achievementService)
    {
        parent::__construct($app);
        $this->achievementService = $achievementService;
    }


    /**业绩详情
     * @return Json
     */
    public function info():Json
    {
        $params = $this->request->get();
        $this->validate(
            $params,
            [
                'agent_user_id|代理用户ID' => 'require'
            ]
        );
        $agent_user_id = $params['agent_user_id'];
        $res = $this->achievementService->getInfo($agent_user_id);
        return $this->renderSuccess($res);
    }

    /**总览业绩
     * @return Json
     */
    public function index():Json
    {
        $params = $this->request->get();
        $this->validate(
            $params,
            [
                //'start_time|开始时间' => '',
                //'end_time|结束时间' => '',
                'page' => 'integer',
                'limit' => 'integer',
                'agent_user_id|代理用户ID' => 'integer'
            ]
        );
        $list = $this->achievementService->getIndex($params);
        return $this->renderSuccess(compact('list'));
    }
}
